import subprocess
import string
import shutil
import random
import os

devnull = open(os.devnull, 'w')

randkey = str()

if os.path.exists('./dist'):
    shutil.rmtree('./dist')

for i in range(16):
    randkey += random.choice(string.ascii_letters)

print('正在构建 ...')
subprocess.run(('pyinstaller', '-F', 'user.py', '-n', 'bdTalk', '-i=NONE', '--key={}'.format(randkey)), stdout=devnull, stderr=devnull)

print('正在处理文件 ...')
os.rename('./dist/bdTalk.exe', './dist/bdTalk.execute')
os.remove('./bdTalk.spec')
shutil.rmtree('./__pycache__')
shutil.rmtree('./build')
shutil.copy('./starter/bdTalk/x64/Release/bdTalk.exe', './dist/bdTalk.exe')
